/*
 * @Author: chenzanjing
 * @Date: 2023-09-25 14:59:53
 * @LastEditors: chenzanjing
 * @LastEditTime: 2023-11-03 08:57:53
 * @FilePath: \zhiji-manage-front\src\api\modules\xinwei-auth\index.ts
 * @Description:
 *
 * Copyright (c) 2023 by ${sylar}, All Rights Reserved.
 */
import { AUTH } from "../../config/servicePort";
import http from "@/api";
import { Login } from "@/api/interface/index";
/** 对应 xinwei-auth 微服务 */

export default class System {
  /** 获取字典数据 */
  getAllDictsList() {
    return http.get<any[]>(`/auth/dict/type/list`);
  }

  loginApi = (params: Login.ReqLoginForm) => {
    return http.post<Login.ResLogin>(`/auth/login`, params, { noLoading: true });
  };

  /** 获取用户数据 */
  getUserProfile = () => {
    return http.get<any>("/user/getInfo");
  };
  /** 获取用户路由数据 */
  getRoutes = () => {
    // http.get("/menu/getRouters");
    // return Promise.resolve({
    //   data: [
    //     {
    //       backStage: 2,
    //       name: "首页",
    //       enName: "Home",
    //       permission: "",
    //       type: 2,
    //       sort: 1,
    //       parentId: 0,
    //       path: "/home",
    //       routeName: "home",
    //       icon: "HomeFilled",
    //       component: "/home/index",
    //       status: 0,
    //       visible: true,
    //       keepAlive: true,
    //       redirectUrl: "",
    //       isLink: false,
    //       linkHref: "",
    //       isFull: false,
    //       activeMenu: "",
    //       id: 1456,
    //       createTime: 1687233067000,
    //       isAffix: true,
    //     },
    //     {
    //       id: 1482,
    //       backStage: 2,
    //       parentId: 0,
    //       name: "系统管理",
    //       enName: "System Manager",
    //       path: "/system",
    //       routeName: "system",
    //       component: null,
    //       icon: "UserFilled",
    //       visible: true,
    //       keepAlive: true,
    //       redirectUrl: "/system/menu",
    //       isLink: false,
    //       linkHref: "",
    //       isFull: false,
    //       activeMenu: "",
    //       children: [
    //         {
    //           id: 1484,
    //           backStage: 2,
    //           parentId: 1482,
    //           name: "菜单管理",
    //           enName: "Menu Manager",
    //           path: "/system/menu",
    //           routeName: "systemMenu",
    //           component: "/system/menu/index",
    //           icon: "Menu",
    //           visible: true,
    //           keepAlive: true,
    //           redirectUrl: "",
    //           isLink: false,
    //           linkHref: "",
    //           isFull: false,
    //           activeMenu: "",
    //           children: null,
    //         },
    //         {
    //           id: 1505,
    //           backStage: 2,
    //           parentId: 1482,
    //           name: "用户管理",
    //           enName: "account Manager",
    //           path: "/system/account",
    //           routeName: "systemAccount",
    //           component: "/system/account/index",
    //           icon: "User",
    //           visible: true,
    //           keepAlive: true,
    //           redirectUrl: "",
    //           isLink: false,
    //           linkHref: "",
    //           isFull: false,
    //           activeMenu: "",
    //           children: null,
    //         },
    //       ],
    //     },
    //   ],
    // });
    return http.get("/menu/getRouters");
  };
  /** 发送手机验证码 */
  sendSmsCode = data => {
    return http.post(`${AUTH}/send-sms-code`, data);
  };
  /** 通过手机号，验证码修改密码 */
  updatePwdByPhone = params => {
    return http.put(AUTH + "/user/info/resetPwdByPhone", params);
  };

  /** 通过修改密码验证码 */
  sendSmsCodeRecoverPwd = data => {
    return http.post(AUTH + "/send-sms-code-recoverPwd", data);
  };
  /** 修改密码 */
  updatePwd = data => {
    return http.put(AUTH + "/user/info/updatePwd", data);
  };

  /**  用户退出登录*/
  logoutApi = () => {
    return http.delete(`/auth/logout`);
  };

  /**用户绑定手机 */
  userBindPhone = data => {
    return http.post(`${AUTH}/user/info/bindPhone`, data);
  };

  /** 获取部门列表 */
  getDeptList = params => {
    return http.get(`/dept/list`, params);
  };
  /**添加部门 */
  addDept = data => {
    return http.post(`/dept`, data);
  };
  /** 修改部门 */
  putDept = data => {
    return http.put(`/dept`, data);
  };
  /** 删除部门 */
  deleteDept = data => {
    return http.delete(`/dept/${data.id}`);
  };
  /** 获取角色列表 */
  getRoleList = params => {
    return http.get<IResponse.IPageData>(`/role/list`, params);
  };
  /** 添加角色 */
  addRole = data => {
    return http.post(`/role`, data);
  };
  /** 修改角色 */
  putRole = data => {
    return http.put(`/role`, data);
  };
  /** 删除角色 */
  deleteRole = data => {
    return http.delete(`/role/${data.id}`);
  };

  /** 获取用户列表 */
  getUserList = params => {
    return http.get(`/user/list`, params);
  };
  /** 添加用户 */
  addUser = data => {
    return http.post(`/user/add`, data);
  };
  /** 修改用户 */
  updateUser = data => {
    return http.put(`/user/update`, data);
  };
}
